package com.hdaccp.goodsprovider.service.Impl;

import com.hdaccp.goodsprovider.service.GoodsService;
import org.main.bean.POJO.PGoods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {

@Autowired
private EntityManager entityManager;
    @Override
    public List<PGoods> queryPage(int currentPage, int pageSize) {
        //写查询表方法用jpa1接收
        String jpa1="select g from Goods g";
        //用query对象接收entitymanager调createQuery方法
        Query query=entityManager.createQuery(jpa1);
        //query调setFirstResult方法
        query.setFirstResult((currentPage-1)*pageSize);
        query.setMaxResults(pageSize);

        return query.getResultList();
    }
}
